
package ru.kpm.rectpack.represent;

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.util.List;

/**
 *
 * @author Podorov Alexander
 */

public class Pallet2DModel extends Model2D
{
    public Pallet2DModel(InputData inputData, OutputData outputData)
    {
        super(inputData, outputData);
    }

    public void paintComponent(Graphics graphics)
    {
        if (inputData.getPy() > 0)
        {
            topOffset = 10;
            scale = (double)(getHeight() - 2 * topOffset) / inputData.getPy();
            leftOffset = (int)(getWidth() - scale * inputData.getPx()) / 2;

            Graphics2D graphics2D = (Graphics2D)graphics;

            graphics2D.setStroke(STROKE);

            graphics.setColor(CONTAINER_COLOR);
            graphics.fillRect(leftOffset, topOffset, (int)(inputData.getPx() * scale), (int)(inputData.getPy() * scale));
            graphics.setColor(BORDER_COLOR);
            graphics.drawRect(leftOffset, topOffset, (int)(inputData.getPx() * scale), (int)(inputData.getPy() * scale));

            List<Rectangle> packs = outputData.getPacks().get(0);            
            for (Rectangle rectangle : packs)
            {
                graphics.setColor(ITEM_COLOR);
                graphics.fillRect(leftOffset + (int)(rectangle.getX() * scale), topOffset + (int)(rectangle.getY() * scale), (int)(rectangle.getWidth() * scale), (int)(rectangle.getHeight() * scale));
                graphics.setColor(BORDER_COLOR);
                graphics.drawRect(leftOffset + (int)(rectangle.getX() * scale), topOffset + (int)(rectangle.getY() * scale), (int)(rectangle.getWidth() * scale), (int)(rectangle.getHeight() * scale));
            }
        }
    }
}
